#include "viml/memory_manager.h"

namespace viml {

// 静态成员变量定义
std::atomic<size_t> MemoryManager::total_allocations{0};
std::atomic<size_t> MemoryManager::total_deallocations{0};
std::atomic<size_t> MemoryManager::current_allocations{0};

void MemoryManager::notify_allocation() {
    total_allocations.fetch_add(1, std::memory_order_relaxed);
    current_allocations.fetch_add(1, std::memory_order_relaxed);
}

void MemoryManager::notify_deallocation() {
    total_deallocations.fetch_add(1, std::memory_order_relaxed);
    current_allocations.fetch_sub(1, std::memory_order_relaxed);
}

size_t MemoryManager::get_total_allocations() {
    return total_allocations.load(std::memory_order_relaxed);
}

size_t MemoryManager::get_total_deallocations() {
    return total_deallocations.load(std::memory_order_relaxed);
}

size_t MemoryManager::get_current_allocations() {
    return current_allocations.load(std::memory_order_relaxed);
}

void MemoryManager::reset_statistics() {
    total_allocations.store(0, std::memory_order_relaxed);
    total_deallocations.store(0, std::memory_order_relaxed);
    current_allocations.store(0, std::memory_order_relaxed);
}

} // namespace viml